<?php 
	namespace Home\Model;
	use Think\Model;

	Class ProgramProvinceModel extends Model
	{
		protected $trueTableName = "program_province";

		public function get_program($province_ids,$page,$rows,$sort,$order,$program_name,$province_name)
		{
			$province_ids && $map['province_id'] = array("in",$province_ids);
			$res = $this->where($map)->select();
			// dump($res);exit();
			// 处理节目数据
			$pro = [];
			foreach ($res as $key => $value) {
				$pro[] = $value['program_id'];
			}
			$pro = array_unique($pro);
			// dump($pro);exit();
			return D("Program")->get_programs($pro,$page,$rows,$sort,$order,$program_name,$province_name);
		}	

		// 获取省份id
		public function get_provinceid($id,$province_name)
		{
			// dump($id);dump($province_name);   //根据获取到的节目id查取该节目属于的省份id
			$res = $this->where(array("program_id"=>$id))->field("program_id,province_id")->select();
			// dump($res);exit;       //获取到省份id
			foreach ($res as $key => $value) {
				$ids[] = $value['province_id'];
			}
			// dump($ids);exit;   
			$a = D("Province")->get_provincename($ids,$id,$province_name);
			// dump($a);exit();
			return $a;
		}

	}
 ?>
